package com.reebake.ideal.security.util;

import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.core.SpringSecurityMessageSource;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class AuthenticationExceptionUtil {
    private static final MessageSourceAccessor messages = SpringSecurityMessageSource.getAccessor();

    public static BadCredentialsException throwBadCredential() {
        throw new BadCredentialsException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"));
    }

    public static BadCredentialsException throwUserNotFound(String username) {
        throw new UsernameNotFoundException(messages.getMessage("JdbcDaoImpl.notFound", new Object[] {username}, "User Not Found"));
    }

    public static AuthenticationCredentialsNotFoundException throwAuthenticationCredentialsNotFoundException() {
        throw new AuthenticationCredentialsNotFoundException(messages.getMessage("AbstractSecurityInterceptor.authenticationNotFound", "Authentication Not Found"));
    }
}
